<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="单位中文名称" prop="chineseName">
      <el-input v-model="dataForm.chineseName" placeholder="单位中文名称"></el-input>
    </el-form-item>
    <el-form-item label="申报人数" prop="applicantsNumber">
      <el-input v-model="dataForm.applicantsNumber" placeholder="申报人数"></el-input>
    </el-form-item>
    <el-form-item label="保险补贴标准" prop="insuranceSubsidyStandard">
      <el-input v-model="dataForm.insuranceSubsidyStandard" placeholder="保险补贴标准"></el-input>
    </el-form-item>
    <el-form-item label="岗位补贴标准" prop="postSubsidyStandard">
      <el-input v-model="dataForm.postSubsidyStandard" placeholder="岗位补贴标准"></el-input>
    </el-form-item>
    <el-form-item label="保险补贴金额" prop="insuranceSubsudyMonths">
      <el-input v-model="dataForm.insuranceSubsudyMonths" placeholder="保险补贴金额"></el-input>
    </el-form-item>
    <el-form-item label="岗位补贴金额" prop="postSubsidyMonths">
      <el-input v-model="dataForm.postSubsidyMonths" placeholder="岗位补贴金额"></el-input>
    </el-form-item>
    <el-form-item label="岗位补贴总金额" prop="totalInsurance">
      <el-input v-model="dataForm.totalInsurance" placeholder="岗位补贴总金额"></el-input>
    </el-form-item>
    <el-form-item label="总金额" prop="totalPost">
      <el-input v-model="dataForm.totalPost" placeholder="总金额"></el-input>
    </el-form-item>
    <el-form-item label="" prop="total">
      <el-input v-model="dataForm.total" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="单位注册地址" prop="redisteredAddressCompany">
      <el-input v-model="dataForm.redisteredAddressCompany" placeholder="单位注册地址"></el-input>
    </el-form-item>
    <el-form-item label="补贴所属县区" prop="areaCountySubsidy">
      <el-input v-model="dataForm.areaCountySubsidy" placeholder="补贴所属县区"></el-input>
    </el-form-item>
    <el-form-item label="补贴所属街道" prop="areaStreetSubsidy">
      <el-input v-model="dataForm.areaStreetSubsidy" placeholder="补贴所属街道"></el-input>
    </el-form-item>
    <el-form-item label="工商业执照号码" prop="license">
      <el-input v-model="dataForm.license" placeholder="工商业执照号码"></el-input>
    </el-form-item>
    <el-form-item label="批次号" prop="batchNumber">
      <el-input v-model="dataForm.batchNumber" placeholder="批次号"></el-input>
    </el-form-item>
    <el-form-item label="账户类型" prop="accountType">
      <el-input v-model="dataForm.accountType" placeholder="账户类型"></el-input>
    </el-form-item>
    <el-form-item label="开户银行" prop="depositBank">
      <el-input v-model="dataForm.depositBank" placeholder="开户银行"></el-input>
    </el-form-item>
    <el-form-item label="银行账号" prop="bankAccount">
      <el-input v-model="dataForm.bankAccount" placeholder="银行账号"></el-input>
    </el-form-item>
    <el-form-item label="联系人" prop="contactPerson">
      <el-input v-model="dataForm.contactPerson" placeholder="联系人"></el-input>
    </el-form-item>
    <el-form-item label="联系电话" prop="telephone">
      <el-input v-model="dataForm.telephone" placeholder="联系电话"></el-input>
    </el-form-item>
    <el-form-item label="经办人" prop="operator">
      <el-input v-model="dataForm.operator" placeholder="经办人"></el-input>
    </el-form-item>
    <el-form-item label="经办机构" prop="agency">
      <el-input v-model="dataForm.agency" placeholder="经办机构"></el-input>
    </el-form-item>
    <el-form-item label="经办日期" prop="agencyDate">
      <el-input v-model="dataForm.agencyDate" placeholder="经办日期"></el-input>
    </el-form-item>
    <el-form-item label="受理人" prop="acceptancePerson">
      <el-input v-model="dataForm.acceptancePerson" placeholder="受理人"></el-input>
    </el-form-item>
    <el-form-item label="受理机构" prop="acceptanceInstitution">
      <el-input v-model="dataForm.acceptanceInstitution" placeholder="受理机构"></el-input>
    </el-form-item>
    <el-form-item label="受理标志" prop="acceptanceMark">
      <el-input v-model="dataForm.acceptanceMark" placeholder="受理标志"></el-input>
    </el-form-item>
    <el-form-item label="受理时间" prop="acceptanceTime">
      <el-input v-model="dataForm.acceptanceTime" placeholder="受理时间"></el-input>
    </el-form-item>
    <el-form-item label="受理说明" prop="acceptanceExplain">
      <el-input v-model="dataForm.acceptanceExplain" placeholder="受理说明"></el-input>
    </el-form-item>
    <el-form-item label="审核人" prop="auditingPerson">
      <el-input v-model="dataForm.auditingPerson" placeholder="审核人"></el-input>
    </el-form-item>
    <el-form-item label="审核机构" prop="auditingInstitution">
      <el-input v-model="dataForm.auditingInstitution" placeholder="审核机构"></el-input>
    </el-form-item>
    <el-form-item label="审核标志" prop="auditingMark">
      <el-input v-model="dataForm.auditingMark" placeholder="审核标志"></el-input>
    </el-form-item>
    <el-form-item label="审核时间" prop="auditingTime">
      <el-input v-model="dataForm.auditingTime" placeholder="审核时间"></el-input>
    </el-form-item>
    <el-form-item label="创建时间" prop="createTime">
      <el-input v-model="dataForm.createTime" placeholder="创建时间"></el-input>
    </el-form-item>
    <el-form-item label="审核说明" prop="auditingExplain">
      <el-input v-model="dataForm.auditingExplain" placeholder="审核说明"></el-input>
    </el-form-item>
    <el-form-item label="修改时间" prop="editTime">
      <el-input v-model="dataForm.editTime" placeholder="修改时间"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          chineseName: '',
          applicantsNumber: '',
          insuranceSubsidyStandard: '',
          postSubsidyStandard: '',
          insuranceSubsudyMonths: '',
          postSubsidyMonths: '',
          totalInsurance: '',
          totalPost: '',
          total: '',
          redisteredAddressCompany: '',
          areaCountySubsidy: '',
          areaStreetSubsidy: '',
          license: '',
          batchNumber: '',
          accountType: '',
          depositBank: '',
          bankAccount: '',
          contactPerson: '',
          telephone: '',
          operator: '',
          agency: '',
          agencyDate: '',
          acceptancePerson: '',
          acceptanceInstitution: '',
          acceptanceMark: '',
          acceptanceTime: '',
          acceptanceExplain: '',
          auditingPerson: '',
          auditingInstitution: '',
          auditingMark: '',
          auditingTime: '',
          createTime: '',
          auditingExplain: '',
          editTime: ''
        },
        dataRule: {
          chineseName: [
            { required: true, message: '单位中文名称不能为空', trigger: 'blur' }
          ],
          applicantsNumber: [
            { required: true, message: '申报人数不能为空', trigger: 'blur' }
          ],
          insuranceSubsidyStandard: [
            { required: true, message: '保险补贴标准不能为空', trigger: 'blur' }
          ],
          postSubsidyStandard: [
            { required: true, message: '岗位补贴标准不能为空', trigger: 'blur' }
          ],
          insuranceSubsudyMonths: [
            { required: true, message: '保险补贴金额不能为空', trigger: 'blur' }
          ],
          postSubsidyMonths: [
            { required: true, message: '岗位补贴金额不能为空', trigger: 'blur' }
          ],
          totalInsurance: [
            { required: true, message: '岗位补贴总金额不能为空', trigger: 'blur' }
          ],
          totalPost: [
            { required: true, message: '总金额不能为空', trigger: 'blur' }
          ],
          total: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          redisteredAddressCompany: [
            { required: true, message: '单位注册地址不能为空', trigger: 'blur' }
          ],
          areaCountySubsidy: [
            { required: true, message: '补贴所属县区不能为空', trigger: 'blur' }
          ],
          areaStreetSubsidy: [
            { required: true, message: '补贴所属街道不能为空', trigger: 'blur' }
          ],
          license: [
            { required: true, message: '工商业执照号码不能为空', trigger: 'blur' }
          ],
          batchNumber: [
            { required: true, message: '批次号不能为空', trigger: 'blur' }
          ],
          accountType: [
            { required: true, message: '账户类型不能为空', trigger: 'blur' }
          ],
          depositBank: [
            { required: true, message: '开户银行不能为空', trigger: 'blur' }
          ],
          bankAccount: [
            { required: true, message: '银行账号不能为空', trigger: 'blur' }
          ],
          contactPerson: [
            { required: true, message: '联系人不能为空', trigger: 'blur' }
          ],
          telephone: [
            { required: true, message: '联系电话不能为空', trigger: 'blur' }
          ],
          operator: [
            { required: true, message: '经办人不能为空', trigger: 'blur' }
          ],
          agency: [
            { required: true, message: '经办机构不能为空', trigger: 'blur' }
          ],
          agencyDate: [
            { required: true, message: '经办日期不能为空', trigger: 'blur' }
          ],
          acceptancePerson: [
            { required: true, message: '受理人不能为空', trigger: 'blur' }
          ],
          acceptanceInstitution: [
            { required: true, message: '受理机构不能为空', trigger: 'blur' }
          ],
          acceptanceMark: [
            { required: true, message: '受理标志不能为空', trigger: 'blur' }
          ],
          acceptanceTime: [
            { required: true, message: '受理时间不能为空', trigger: 'blur' }
          ],
          acceptanceExplain: [
            { required: true, message: '受理说明不能为空', trigger: 'blur' }
          ],
          auditingPerson: [
            { required: true, message: '审核人不能为空', trigger: 'blur' }
          ],
          auditingInstitution: [
            { required: true, message: '审核机构不能为空', trigger: 'blur' }
          ],
          auditingMark: [
            { required: true, message: '审核标志不能为空', trigger: 'blur' }
          ],
          auditingTime: [
            { required: true, message: '审核时间不能为空', trigger: 'blur' }
          ],
          createTime: [
            { required: true, message: '创建时间不能为空', trigger: 'blur' }
          ],
          auditingExplain: [
            { required: true, message: '审核说明不能为空', trigger: 'blur' }
          ],
          editTime: [
            { required: true, message: '修改时间不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/generator/comparedata/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.chineseName = data.compareData.chineseName
                this.dataForm.applicantsNumber = data.compareData.applicantsNumber
                this.dataForm.insuranceSubsidyStandard = data.compareData.insuranceSubsidyStandard
                this.dataForm.postSubsidyStandard = data.compareData.postSubsidyStandard
                this.dataForm.insuranceSubsudyMonths = data.compareData.insuranceSubsudyMonths
                this.dataForm.postSubsidyMonths = data.compareData.postSubsidyMonths
                this.dataForm.totalInsurance = data.compareData.totalInsurance
                this.dataForm.totalPost = data.compareData.totalPost
                this.dataForm.total = data.compareData.total
                this.dataForm.redisteredAddressCompany = data.compareData.redisteredAddressCompany
                this.dataForm.areaCountySubsidy = data.compareData.areaCountySubsidy
                this.dataForm.areaStreetSubsidy = data.compareData.areaStreetSubsidy
                this.dataForm.license = data.compareData.license
                this.dataForm.batchNumber = data.compareData.batchNumber
                this.dataForm.accountType = data.compareData.accountType
                this.dataForm.depositBank = data.compareData.depositBank
                this.dataForm.bankAccount = data.compareData.bankAccount
                this.dataForm.contactPerson = data.compareData.contactPerson
                this.dataForm.telephone = data.compareData.telephone
                this.dataForm.operator = data.compareData.operator
                this.dataForm.agency = data.compareData.agency
                this.dataForm.agencyDate = data.compareData.agencyDate
                this.dataForm.acceptancePerson = data.compareData.acceptancePerson
                this.dataForm.acceptanceInstitution = data.compareData.acceptanceInstitution
                this.dataForm.acceptanceMark = data.compareData.acceptanceMark
                this.dataForm.acceptanceTime = data.compareData.acceptanceTime
                this.dataForm.acceptanceExplain = data.compareData.acceptanceExplain
                this.dataForm.auditingPerson = data.compareData.auditingPerson
                this.dataForm.auditingInstitution = data.compareData.auditingInstitution
                this.dataForm.auditingMark = data.compareData.auditingMark
                this.dataForm.auditingTime = data.compareData.auditingTime
                this.dataForm.createTime = data.compareData.createTime
                this.dataForm.auditingExplain = data.compareData.auditingExplain
                this.dataForm.editTime = data.compareData.editTime
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/generator/comparedata/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'chineseName': this.dataForm.chineseName,
                'applicantsNumber': this.dataForm.applicantsNumber,
                'insuranceSubsidyStandard': this.dataForm.insuranceSubsidyStandard,
                'postSubsidyStandard': this.dataForm.postSubsidyStandard,
                'insuranceSubsudyMonths': this.dataForm.insuranceSubsudyMonths,
                'postSubsidyMonths': this.dataForm.postSubsidyMonths,
                'totalInsurance': this.dataForm.totalInsurance,
                'totalPost': this.dataForm.totalPost,
                'total': this.dataForm.total,
                'redisteredAddressCompany': this.dataForm.redisteredAddressCompany,
                'areaCountySubsidy': this.dataForm.areaCountySubsidy,
                'areaStreetSubsidy': this.dataForm.areaStreetSubsidy,
                'license': this.dataForm.license,
                'batchNumber': this.dataForm.batchNumber,
                'accountType': this.dataForm.accountType,
                'depositBank': this.dataForm.depositBank,
                'bankAccount': this.dataForm.bankAccount,
                'contactPerson': this.dataForm.contactPerson,
                'telephone': this.dataForm.telephone,
                'operator': this.dataForm.operator,
                'agency': this.dataForm.agency,
                'agencyDate': this.dataForm.agencyDate,
                'acceptancePerson': this.dataForm.acceptancePerson,
                'acceptanceInstitution': this.dataForm.acceptanceInstitution,
                'acceptanceMark': this.dataForm.acceptanceMark,
                'acceptanceTime': this.dataForm.acceptanceTime,
                'acceptanceExplain': this.dataForm.acceptanceExplain,
                'auditingPerson': this.dataForm.auditingPerson,
                'auditingInstitution': this.dataForm.auditingInstitution,
                'auditingMark': this.dataForm.auditingMark,
                'auditingTime': this.dataForm.auditingTime,
                'createTime': this.dataForm.createTime,
                'auditingExplain': this.dataForm.auditingExplain,
                'editTime': this.dataForm.editTime
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
